package tech.wenxu.curekaconsumer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import tech.wenxu.curekaconsumer.fegin.HelloService;

/**
 * 不做业务，去调用服务的提供者
 * @author zhaowenxu
 * @date 2020/4/11 13:23
 */
@RestController
public class HelloController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private HelloService helloService;

    /**
     * 使用restTemplate和fegin调用服务提供者
     */
    @GetMapping("/hello/{name}")
    public String hello(@PathVariable String name) {
        // 使用restTemplate
        String url = "http://localhost:7900/hello/" + name;
        url = "http://provider-user:7900/hello/" + name;
        String result = restTemplate.getForObject(url, String.class);

        // 使用fegin
        String helloResult = helloService.hello(name);
        return helloResult;
    }

}
